package com.sjr.easy.chat.app.utils;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;

import java.nio.charset.StandardCharsets;

@Slf4j
public class RabbitMessageUtils {

    public static String messageBodyAsString(Message message) {
        return new String(message.getBody(), StandardCharsets.UTF_8);
    }


    public static <T> T messageBodyAsObject(Message message, Class<T> clazz) {
        String jsonStr = messageBodyAsString(message);
        log.info("jsonStr:{}", jsonStr);
        return JSON.parseObject(jsonStr, clazz);
    }

}
